#################
# Appendix      #    
# Figure 13     #
#################


##################screen setting############

windows(30,25)
par(mfrow=c(2,3)) 



##################TSCA:USA############################
#load data
tb_usa_mpcomparison<-read.csv("tb_usa_mpcomparison_rep.csv")
attach(tb_usa_mpcomparison)

#change colnames
summary(tb_usa_mpcomparison)
df_tsclust1<-tb_usa_mpcomparison[,c(-1,-2)]
colnames(df_tsclust1)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust1 <- diss(df_tsclust1, "DTWARP")
d_dtw_clust1
# hclust with complete method
h1 <- hclust(d_dtw_clust1)

plot(h1,main="US(Republican)" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:UK############################
#load data
tb_uk_mpcomparison<-read.csv("tb_uk_mpcomparison_lab.csv")
attach(tb_uk_mpcomparison)

#change colnames
summary(tb_uk_mpcomparison)
df_tsclust2<-tb_uk_mpcomparison[,c(-1,-2)]
colnames(df_tsclust2)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust2 <- diss(df_tsclust2, "DTWARP")
d_dtw_clust2
# hclust with complete method
h2 <- hclust(d_dtw_clust2)

plot(h2,main="UK(Labour)" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:GERMANY############################
#load data
tb_german_mpcomparison<-read.csv("tb_german_mpcomparison_spd.csv")
attach(tb_german_mpcomparison)

#change colnames
summary(tb_german_mpcomparison)
df_tsclust4<-tb_german_mpcomparison[,c(-1,-2)]
colnames(df_tsclust4)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust4 <- diss(df_tsclust4, "DTWARP")
d_dtw_clust4
# hclust with complete method
h4 <- hclust(d_dtw_clust4)
plot(h4,main="GERMANY(SPD)" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:DENMARK############################
#load data
tb_denmark_mpcomparison<-read.csv("tb_denmark_mpcomparison_kons.csv")
attach(tb_denmark_mpcomparison)

#change colnames
summary(tb_denmark_mpcomparison)
df_tsclust5<-tb_denmark_mpcomparison[,c(-1,-2)]
colnames(df_tsclust5)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust5 <- diss(na.omit(df_tsclust5), "DTWARP")
d_dtw_clust5
# hclust with complete method
h5 <- hclust(d_dtw_clust5)
plot(h5,main="DENMARK(Kons)" ,xlab="cluster(complete method)",hang = -1)

